<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>活动列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css">
	<style>
		.layui-table-body .layui-table-cell{
			height:100px;
			line-height:100px
		}
	</style>
</head>
<body class="childrenBody">
<form class="layui-form" lay-filter="example">
    <blockquote class="layui-elem-quote quoteBox">
            <div class="layui-inline">
				<a class="layui-btn layui-btn-normal refresh">刷新</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-normal addActivity">新增活动</a>
			</div>
			<div class="layui-inline">
				<button type="button" class="layui-btn" onclick="search(1)">未开始</button>
			</div>
			<div class="layui-inline">
			    <button type="button" class="layui-btn" onclick="search(2)">活动中</button>
			</div>
			<div class="layui-inline">
			    <button type="button" class="layui-btn" onclick="search(3)">已结束</button>
			</div>
	</blockquote> 
	<div id="photos">
		<table id="activityList" lay-filter="activityList"></table>
	</div>
</form>

	<!--操作-->
	<script type="text/html" id="activityListBar">
        <a class="layui-btn layui-btn-xs" lay-event="create">链接</a>
        <a class="layui-btn layui-btn-xs" lay-event="query">选手</a>
        <a class="layui-btn layui-btn-xs" lay-event="queryNew">新页</a>
        <a class="layui-btn layui-btn-xs" lay-event="close">启停</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit2">基本修改</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">全部修改</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
	</script>
<script src="/${BasePath}/static/layui/layui.js" charset="utf-8" type="text/javascript"></script>
<script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="/${BasePath}/static/js/common/datatable_common.js"></script>
<script type="text/javascript">
layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    //列表
    var tableIns = table.render({
        elem: '#activityList',
        url : '/${BasePath}/activity/queryActivityPage?',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 20,
        limits : [1,10,15,20,25],
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'title', title: '活动名称', width:600},
            {field: 'startTime', title: '开始时间', width:180},
            {field: 'endTime', title: '结束时间', width:180},
            {field: 'times', title: '可投票次数', width:100},
           /*  {field: 'headpic', title: '宣传图',templet:function(d){
                return '<div style="width:50px;height:100px"><img src="'+d.headpic+'" height="100" width="60" /></div>';
            }, width:100},
            {field: 'activitpic', title: '详情图',templet:function(d){
                return '<img src="'+d.activitpic+'" height="100" width="60" />';
            }, width:100}, */
            {field: 'moneySum', title: '总金额', width:100},
            {field: 'moneyDay', title: '日金额', width:100},
            {field: 'totalnum', title: '总点击量', width:100},
            {field: 'flag', title: '状态',templet: function(d){
	              return d.flag=='Y'?"开启":"关闭"
	          }, width:60},
            {field: 'createTime', title: '创建时间', templet:function(res){return replaceDate(res.createTime / 1000)}, width:140},
            {title: '操作', width:400, templet:'#activityListBar',align:"center",fixed:'right'}
        ]],
        done: function () {
            layer.photos({
                photos: '#photos'
            });
        },
        skin: 'line'
    });
    
    function editActivity(edit){
    	   window.location.href="/${BasePath}/activity/addActivity?id="+edit.id;
    }
    function editActivity2(edit){
 	   window.location.href="/${BasePath}/activity/editActivity?id="+edit.id;
    }
    function queryActivityPlayer(query){
 	   window.location.href="/${BasePath}/activity/playerList?id="+query.id;
    }
    function queryActivityPlayerNew(query){
  	   window.open("/${BasePath}/activity/playerList?id="+query.id);
    }
    $(".addActivity").click(function(){
    	window.location.href="/${BasePath}/activity/addActivity?id="+0;
    })
    $(".refresh").click(function(){
    	window.location.reload();
    })
    //列表操作
    table.on('tool(activityList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;

        if(layEvent === 'edit'){ //编辑
        	editActivity(data);
        } else if(layEvent === 'del'){ //删除
            layer.confirm('确定删除该投票信息？',{icon:3, title:'提示信息'},function(index){
                 $.get("/${BasePath}/activity/deleteActivity",{
                     id : data.id  
                 },function(data){
                    tableIns.reload();
                    layer.close(index);
                 })
            });
        } else if(layEvent === 'query'){
        	queryActivityPlayer(data);
        } else if(layEvent === 'close'){
        	var now=data.flag;
        	var message='确定关闭该投票信息？';
        	if(now=='N'){
        		message='确定开启该投票信息？';
        	}
        	layer.confirm(message,{icon:3, title:'提示信息'},function(index){
                $.get("/${BasePath}/activity/closeActivity",{
                    id : data.id  
                },function(data){
                   tableIns.reload();
                   layer.close(index);
                })
           });
        }else if(layEvent === 'create'){
        	window.location.href="/${BasePath}/activity/createUrl?id="+data.id;
        }else if(layEvent === 'queryNew'){
        	queryActivityPlayerNew(data);
        }else if(layEvent === 'edit2'){
        	editActivity2(data);
        }
    });

})

//查询方法
function search(status){
	var index = layer.msg('数据请求中', {
        icon: 16
        , time: -1
        , anim: -1
        , fixed: false
	});
	layui.use('table', function () {
	var table = layui.table;
	 table.reload('activityList', {
	    	where: {status:status}
	      	, page: {
	              curr: 1
	    	}
	  });
	
	});
	layer.close(index);
	return false;
}
</script>
</body>
</html>